home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 3 / MacMania 3.toast / Tools&Utilities / Workshop v1.0 / Externals / •Code for Externals / Convert CTable Source / ModuleFunctions.c < prev    next >
Encoding:
Text File  |  1994-07-21  |  5.2 KB  |  196 lines  |  [TEXT/MMCC]

  1. /******************************************************************************
  2.     File:        ModuleFunctions.c
  3.  
  4.     Contains:    This file contains the the code to perform the actions of the
  5.                 External Module.
  6.  
  7.     Written by:    Brian Powell
  8.  
  9.     Copyright:    © 1994 by Brian Powell, all rights reserved.
  10.  
  11.  ******************************************************************************/
  12.  
  13. // Include Files
  14. #include "WorkshopModule.h"
  15. #include <StandardFile.h>
  16. #include <stdio.h>
  17.  
  18. /******************************************************************************
  19.  * ModuleInit
  20.  *
  21.  * Image Workshop is initializing.  This is your chance to initialize your
  22.  * module for anything you may need.
  23.  *
  24.  * data1: NULL
  25.  * data2: NULL
  26.  ******************************************************************************/
  27.  
  28. short ModuleInit(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData)
  29. {
  30.     short    error = 0;
  31.     
  32.     return (error);
  33. }
  34.  
  35. /******************************************************************************
  36.  * ModuleRead
  37.  *
  38.  * If your module is a reader, then this code is called to read and create the
  39.  * new image.
  40.  *
  41.  * data1: StandardFileReply *, This is the file to load
  42.  * data2: Boolean *, Whether or not you should create a new image, or merely a
  43.  *            new layer.
  44.  ******************************************************************************/
  45.  
  46. short ModuleRead(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData)
  47. {
  48.     short    error = 0;
  49.     
  50.     return (error);
  51. }
  52.  
  53. /******************************************************************************
  54.  * ModuleSave
  55.  *
  56.  * If your module saves files, then this code is called to save the image.
  57.  *
  58.  * data1: SFReply *, File to save into
  59.  * data2: NULL
  60.  ******************************************************************************/
  61.  
  62. short ModuleSave(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData)
  63. {
  64.     short    error = 0;
  65.     
  66.     return (error);
  67. }
  68.  
  69. /******************************************************************************
  70.  * ModuleExecute
  71.  *
  72.  * If you have a general module, whenever your module is selected by the user,
  73.  * this code is called to execute.
  74.  *
  75.  * data1: NULL
  76.  * data2: NULL
  77.  ******************************************************************************/
  78.  
  79. short ModuleExecute(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData)
  80. {
  81.     short                    error = 0;
  82.     StandardFileReply        reply;
  83.     OSType                    list[1];
  84.     short                    image;
  85.     Str255                    name;
  86.     FILE                    *input;
  87.     char                    line[80];
  88.     short                    r, g, b, count=0;
  89.     RGBColor                color;
  90.     float                    scale = 65535.0/255.0;
  91.     
  92.     // Set up the file parameters
  93.     list[0] = (OSType)'TEXT';
  94.     
  95.     // Let the user choose a file to open
  96.     StandardGetFile(NULL, 1, list, &reply);
  97.     if (reply.sfGood) {
  98.         CTabHandle    cTable;
  99.         
  100.         // Set up the name
  101.         BlockMove(reply.sfFile.name, name, reply.sfFile.name[0]+1);
  102.         name[name[0]+1] = '\0';
  103.         
  104.         // Create a standard 8-bit color table, then hold it down
  105.         cTable = GetCTable(8);
  106.         MoveHHi((Handle)cTable);
  107.         HLock((Handle)cTable);
  108.         
  109.         // Open the file, bringing in the color table
  110.         input = fopen((char *)&(name[1]), "r");
  111.  
  112.         while (!feof(input)) {
  113.             fscanf(input, "%d %d %d\n", &r, &g, &b);
  114.             color.red = (float)r*scale;
  115.             color.green = (float)g*scale;
  116.             color.blue = (float)b*scale;
  117.             (*cTable)->ctTable[count++].rgb = color;
  118.             if (count > 255) break;
  119.         }        
  120.         fclose(input);
  121.         
  122.         // Clean things up
  123.         HUnlock((Handle)cTable);
  124.         
  125.         // Get a file to save into
  126.         StandardPutFile("\pSave Color Table:", name, &reply);
  127.         if (reply.sfGood) {
  128.             short    refNum;
  129.             
  130.             // Save it out
  131.             FSpCreateResFile(&(reply.sfFile), kIWSignature, kIWCTableType, smSystemScript);
  132.             refNum = FSpOpenResFile(&(reply.sfFile), fsRdWrShPerm);
  133.             AddResource((Handle)cTable, 'clut', 128, reply.sfFile.name);
  134.             ReleaseResource((Handle)cTable);
  135.             CloseResFile(refNum);
  136.             
  137.             // Tell the user
  138.             image = functions->GetTopImage();
  139.             if (image) {
  140.                 functions->SetColorTable(image, cTable);
  141.             }
  142.             Alert(128, NULL);
  143.         }
  144.     }
  145.     
  146.     return (error);
  147. }
  148.  
  149. /******************************************************************************
  150.  * ModuleDispose
  151.  *
  152.  * Image Workshop is quitting.  Do any disposal items you need to.
  153.  *
  154.  * data1: NULL
  155.  * data2: NULL
  156.  ******************************************************************************/
  157.  
  158. short ModuleDispose(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData)
  159. {
  160.     short    error = 0;
  161.     
  162.     return (error);
  163. }
  164.  
  165. /******************************************************************************
  166.  * ModuleProcessTask
  167.  *
  168.  * Your task needs processing.  Do an iteration, and let control back.
  169.  *
  170.  * data1:    long*.  Return the percentage complete your function is (0-100).
  171.  * data2:    long*.    The maximum number of ticks you'll allow between calls.
  172.  ******************************************************************************/
  173.  
  174. short ModuleProcessTask(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData)
  175. {
  176.     short    error = 0;
  177.     
  178.     return (error);
  179. }
  180.  
  181. /******************************************************************************
  182.  * ModuleCancelTask
  183.  *
  184.  * The user canceled your task.
  185.  *
  186.  * data1: NULL
  187.  * data2: NULL
  188.  ******************************************************************************/
  189.  
  190. short ModuleCancelTask(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData)
  191. {
  192.     short    error = 0;
  193.     
  194.     return (error);
  195. }
  196.